home *** CD-ROM | disk | FTP | other *** search
/ PC World Komputer 2010 April / PCWorld0410.iso / hity wydania / Ubuntu 9.10 PL / karmelkowy-koliberek-desktop-9.10-i386-PL.iso / casper / filesystem.squashfs / usr / lib / firefox-3.5.5 / run-mozilla.sh < prev   
Linux/UNIX/POSIX Shell Script  |  2009-11-09  |  10KB  |  402 lines

  1. #!/bin/sh
  2. #
  3. # ***** BEGIN LICENSE BLOCK *****
  4. # Version: MPL 1.1/GPL 2.0/LGPL 2.1
  5. #
  6. # The contents of this file are subject to the Mozilla Public License Version
  7. # 1.1 (the "License"); you may not use this file except in compliance with
  8. # the License. You may obtain a copy of the License at
  9. # http://www.mozilla.org/MPL/
  10. #
  11. # Software distributed under the License is distributed on an "AS IS" basis,
  12. # WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
  13. # for the specific language governing rights and limitations under the
  14. # License.
  15. #
  16. # The Original Code is mozilla.org code.
  17. #
  18. # The Initial Developer of the Original Code is
  19. # Netscape Communications Corporation.
  20. # Portions created by the Initial Developer are Copyright (C) 1998
  21. # the Initial Developer. All Rights Reserved.
  22. #
  23. # Contributor(s):
  24. #
  25. # Alternatively, the contents of this file may be used under the terms of
  26. # either of the GNU General Public License Version 2 or later (the "GPL"),
  27. # or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
  28. # in which case the provisions of the GPL or the LGPL are applicable instead
  29. # of those above. If you wish to allow use of your version of this file only
  30. # under the terms of either the GPL or the LGPL, and not to allow others to
  31. # use your version of this file under the terms of the MPL, indicate your
  32. # decision by deleting the provisions above and replace them with the notice
  33. # and other provisions required by the GPL or the LGPL. If you do not delete
  34. # the provisions above, a recipient may use your version of this file under
  35. # the terms of any one of the MPL, the GPL or the LGPL.
  36. #
  37. # ***** END LICENSE BLOCK *****
  38. cmdname=`basename "$0"`
  39. MOZ_DIST_BIN=`dirname "$0"`
  40. MOZ_DEFAULT_NAME="./${cmdname}-bin"
  41. MOZ_APPRUNNER_NAME="./mozilla-bin"
  42. MOZ_VIEWER_NAME="./viewer"
  43. MOZ_PROGRAM=""
  44.  
  45. exitcode=0
  46. #
  47. ##
  48. ## Functions
  49. ##
  50. ##########################################################################
  51. moz_usage()
  52. {
  53. echo "Usage:  ${cmdname} [options] [program]"
  54. echo ""
  55. echo "  options:"
  56. echo ""
  57. echo "    -g                   Run in debugger."
  58. echo "    --debug"
  59. echo ""
  60. echo "    -d debugger          Debugger to use."
  61. echo "    --debugger debugger"
  62. echo ""
  63. echo "  Examples:"
  64. echo ""
  65. echo "  Run the viewer"
  66. echo ""
  67. echo "    ${cmdname} viewer"
  68. echo ""
  69. echo "  Run the mozilla-bin binary"
  70. echo ""
  71. echo "    ${cmdname} mozilla-bin"
  72. echo ""
  73. echo "  Debug the viewer in a debugger"
  74. echo ""
  75. echo "    ${cmdname} -g viewer"
  76. echo ""
  77. echo "  Debug the mozilla-bin binary in gdb"
  78. echo ""
  79. echo "    ${cmdname} -g mozilla-bin -d gdb"
  80. echo ""
  81.     return 0
  82. }
  83. ##########################################################################
  84. moz_bail()
  85. {
  86.     message=$1
  87.     echo
  88.     echo "$cmdname: $message"
  89.     echo
  90.     exit 1
  91. }
  92. ##########################################################################
  93. moz_test_binary()
  94. {
  95.     binary=$1
  96.     if [ -f "$binary" ]
  97.     then
  98.         if [ -x "$binary" ]
  99.         then
  100.             return 1
  101.         fi
  102.     fi
  103.     return 0
  104. }
  105. ##########################################################################
  106. moz_get_debugger()
  107. {
  108.     debuggers="ddd gdb dbx bdb"
  109.     debugger="notfound"
  110.     done="no"
  111.     for d in $debuggers
  112.     do
  113.         moz_test_binary /bin/type
  114.         if [ $? -eq 1 ]
  115.         then
  116.             dpath=`LC_MESSAGES=C type ${d} | awk '{print $3;}' | sed -e 's/\.$//'`    
  117.         else     
  118.             dpath=`which ${d}`    
  119.         fi
  120.         if [ -x "$dpath" ]
  121.         then
  122.             debugger=$dpath
  123.             break
  124.         fi
  125.     done
  126.     echo $debugger
  127.     return 0
  128. }
  129. ##########################################################################
  130. moz_run_program()
  131. {
  132.     prog=$MOZ_PROGRAM
  133.     ##
  134.     ## Make sure the program is executable
  135.     ##
  136.     if [ ! -x "$prog" ]
  137.     then
  138.         moz_bail "Cannot execute $prog."
  139.     fi
  140.     ##
  141.     ## Run the program
  142.     ##
  143.     "$prog" ${1+"$@"}
  144.     exitcode=$?
  145. }
  146. ##########################################################################
  147. moz_debug_program()
  148. {
  149.     prog=$MOZ_PROGRAM
  150.     ##
  151.     ## Make sure the program is executable
  152.     ##
  153.     if [ ! -x "$prog" ]
  154.     then
  155.         moz_bail "Cannot execute $prog."
  156.     fi
  157.     if [ -n "$moz_debugger" ]
  158.     then
  159.         moz_test_binary /bin/type
  160.         if [ $? -eq 1 ]
  161.         then    
  162.             debugger=`LC_MESSAGES=C type $moz_debugger | awk '{print $3;}' | sed -e 's/\.$//'` 
  163.         else
  164.             debugger=`which $moz_debugger` 
  165.         fi    
  166.     else
  167.         debugger=`moz_get_debugger`
  168.     fi
  169.     if [ -x "$debugger" ] 
  170.     then
  171.         tmpfile=`mktemp /tmp/mozargs.XXXXXX` || { echo "Cannot create temporary file" >&2; exit 1; }
  172.         trap " [ -f \"$tmpfile\" ] && /bin/rm -f -- \"$tmpfile\"" 0 1 2 3 13 15
  173.         # echo -n isn't portable, so pipe through perl -pe chomp instead
  174.         echo "set args" | perl -pe 'chomp' > $tmpfile
  175.         for PARAM in "$@"
  176.         do
  177.             echo " '$PARAM'" | perl -pe 'chomp' >> $tmpfile
  178.         done
  179.         echo >> $tmpfile
  180. # If you are not using ddd, gdb and know of a way to convey the arguments 
  181. # over to the prog then add that here- Gagan Saksena 03/15/00
  182.         case `basename $debugger` in
  183.             gdb) echo "$debugger $prog -x $tmpfile"
  184.                 $debugger "$prog" -x $tmpfile
  185.         exitcode=$?
  186.                 ;;
  187.             ddd) echo "$debugger --debugger \"gdb -x $tmpfile\" $prog"
  188.                 $debugger --debugger "gdb -x $tmpfile" "$prog"
  189.         exitcode=$?
  190.                 ;;
  191.             *) echo "$debugger $prog ${1+"$@"}"
  192.                 $debugger "$prog" ${1+"$@"}
  193.         exitcode=$?
  194.                 ;;
  195.         esac
  196.     else
  197.         echo "Could not find a debugger on your system." 
  198.     fi
  199. }
  200. ##########################################################################
  201. ##
  202. ## Command line arg defaults
  203. ##
  204. moz_debug=0
  205. moz_debugger=""
  206. #
  207. ##
  208. ## Parse the command line
  209. ##
  210. while [ $# -gt 0 ]
  211. do
  212.   case $1 in
  213.     -g | --debug)
  214.       moz_debug=1
  215.       shift
  216.       ;;
  217.     -d | --debugger)
  218.       moz_debugger=$2;
  219.       if [ "${moz_debugger}" != "" ]; then
  220.     shift 2
  221.       else
  222.         echo "-d requires an argument"
  223.         exit 1
  224.       fi
  225.       ;;
  226.     *)
  227.       break;
  228.       ;;
  229.   esac
  230. done
  231. #
  232. ##
  233. ## Program name given in $1
  234. ##
  235. if [ $# -gt 0 ]
  236. then
  237.     MOZ_PROGRAM=$1
  238.     shift
  239. fi
  240. ##
  241. ## Program not given, try to guess a default
  242. ##
  243. if [ -z "$MOZ_PROGRAM" ]
  244. then
  245.     ##
  246.     ## Try this script's name with '-bin' appended
  247.     ##
  248.     if [ -x "$MOZ_DEFAULT_NAME" ]
  249.     then
  250.         MOZ_PROGRAM=$MOZ_DEFAULT_NAME
  251.     ## Try viewer (this should be deprecated)
  252.     ## 
  253.     elif [ -x "$MOZ_VIEWER_NAME" ]
  254.     then
  255.         MOZ_PROGRAM=$MOZ_VIEWER_NAME
  256.     ##
  257.     ## Try mozilla-bin
  258.     ## 
  259.     elif [ -x "$MOZ_APPRUNNER_NAME" ]
  260.     then
  261.         MOZ_PROGRAM=$MOZ_APPRUNNER_NAME
  262.     fi
  263. fi
  264. #
  265. #
  266. ##
  267. ## Make sure the program is executable
  268. ##
  269. if [ ! -x "$MOZ_PROGRAM" ]
  270. then
  271.     moz_bail "Cannot execute $MOZ_PROGRAM."
  272. fi
  273. #
  274. ##
  275. ## Set MOZILLA_FIVE_HOME
  276. ##
  277. MOZILLA_FIVE_HOME=$MOZ_DIST_BIN
  278.  
  279. if [ -z "$MRE_HOME" ]; then
  280.     MRE_HOME=$MOZILLA_FIVE_HOME
  281. fi
  282. ##
  283. ## Set LD_LIBRARY_PATH
  284. ##
  285. ## On Solaris we use $ORIGIN (set in RUNPATH) instead of LD_LIBRARY_PATH 
  286. ## to locate shared libraries. 
  287. ##
  288. ## When a shared library is a symbolic link, $ORIGIN will be replaced with
  289. ## the real path (i.e., what the symbolic link points to) by the runtime
  290. ## linker.  For example, if dist/bin/libxul.so is a symbolic link to
  291. ## toolkit/library/libxul.so, $ORIGIN will be "toolkit/library" instead of "dist/bin".
  292. ## So the runtime linker will use "toolkit/library" NOT "dist/bin" to locate the
  293. ## other shared libraries that libxul.so depends on.  This only happens
  294. ## when a user (developer) tries to start firefox, thunderbird, or seamonkey
  295. ## under dist/bin. To solve the problem, we should rely on LD_LIBRARY_PATH
  296. ## to locate shared libraries.
  297. ##
  298. ## Note: 
  299. ##  We test $MOZ_DIST_BIN/*.so. If any of them is a symbolic link,
  300. ##  we need to set LD_LIBRARY_PATH.
  301. ##########################################################################
  302. moz_should_set_ld_library_path()
  303. {
  304.     [ `uname -s` != "SunOS" ] && return 0
  305.     for sharedlib in $MOZ_DIST_BIN/*.so
  306.     do
  307.         [ -h $sharedlib ] && return 0
  308.     done
  309.     return 1
  310. }
  311. if moz_should_set_ld_library_path
  312. then
  313.     LD_LIBRARY_PATH=${MOZ_DIST_BIN}:${MOZ_DIST_BIN}/plugins:${MRE_HOME}${LD_LIBRARY_PATH+":$LD_LIBRARY_PATH"}
  314. fi 
  315.  
  316. if [ -n "$LD_LIBRARYN32_PATH" ]
  317. then
  318.     LD_LIBRARYN32_PATH=${MOZ_DIST_BIN}:${MOZ_DIST_BIN}/plugins:${MRE_HOME}${LD_LIBRARYN32_PATH+":$LD_LIBRARYN32_PATH"}
  319. fi
  320. if [ -n "$LD_LIBRARYN64_PATH" ]
  321. then
  322.     LD_LIBRARYN64_PATH=${MOZ_DIST_BIN}:${MOZ_DIST_BIN}/plugins:${MRE_HOME}${LD_LIBRARYN64_PATH+":$LD_LIBRARYN64_PATH"}
  323. fi
  324. if [ -n "$LD_LIBRARY_PATH_64" ]; then
  325.     LD_LIBRARY_PATH_64=${MOZ_DIST_BIN}:${MOZ_DIST_BIN}/plugins:${MRE_HOME}${LD_LIBRARY_PATH_64+":$LD_LIBRARY_PATH_64"}
  326. fi
  327. #
  328. #
  329. ## Set SHLIB_PATH for HPUX
  330. SHLIB_PATH=${MOZ_DIST_BIN}:${MRE_HOME}${SHLIB_PATH+":$SHLIB_PATH"}
  331. #
  332. ## Set LIBPATH for AIX
  333. LIBPATH=${MOZ_DIST_BIN}:${MRE_HOME}${LIBPATH+":$LIBPATH"}
  334. #
  335. ## Set DYLD_LIBRARY_PATH for Mac OS X (Darwin)
  336. DYLD_LIBRARY_PATH=${MOZ_DIST_BIN}:${MRE_HOME}${DYLD_LIBRARY_PATH+":$DYLD_LIBRARY_PATH"}
  337. #
  338. ## Set LIBRARY_PATH for BeOS
  339. LIBRARY_PATH=${MOZ_DIST_BIN}:${MOZ_DIST_BIN}/components:${MRE_HOME}${LIBRARY_PATH+":$LIBRARY_PATH"}
  340. #
  341. ## Set ADDON_PATH for BeOS
  342. ADDON_PATH=${MOZ_DIST_BIN}${ADDON_PATH+":$ADDON_PATH"}
  343. #
  344. ## Solaris Xserver(Xsun) tuning - use shared memory transport if available
  345. if [ "$XSUNTRANSPORT" = "" ]
  346. then 
  347.         XSUNTRANSPORT="shmem" 
  348.         XSUNSMESIZE="512"
  349.         export XSUNTRANSPORT XSUNSMESIZE
  350. fi
  351.  
  352. # Disable Gnome crash dialog
  353. GNOME_DISABLE_CRASH_DIALOG=1
  354. export GNOME_DISABLE_CRASH_DIALOG
  355.  
  356. if [ "$moz_debug" -eq 1 ]
  357. then
  358.   echo "MOZILLA_FIVE_HOME=$MOZILLA_FIVE_HOME"
  359.   echo "  LD_LIBRARY_PATH=$LD_LIBRARY_PATH"
  360.   if [ -n "$LD_LIBRARYN32_PATH" ]
  361.   then
  362.       echo "LD_LIBRARYN32_PATH=$LD_LIBRARYN32_PATH"
  363.   fi
  364.   if [ -n "$LD_LIBRARYN64_PATH" ]
  365.   then
  366.       echo "LD_LIBRARYN64_PATH=$LD_LIBRARYN64_PATH"
  367.   fi
  368.   if [ -n "$LD_LIBRARY_PATH_64" ]; then
  369.       echo "LD_LIBRARY_PATH_64=$LD_LIBRARY_PATH_64"
  370.   fi
  371.   if [ -n "$DISPLAY" ]; then
  372.        echo "DISPLAY=$DISPLAY"
  373.   fi
  374.   if [ -n "$FONTCONFIG_PATH" ]; then
  375.     echo "FONTCONFIG_PATH=$FONTCONFIG_PATH"
  376.   fi
  377.   if [ -n "$MOZILLA_POSTSCRIPT_PRINTER_LIST" ]; then
  378.        echo "MOZILLA_POSTSCRIPT_PRINTER_LIST=$MOZILLA_POSTSCRIPT_PRINTER_LIST"
  379.   fi
  380.   echo "DYLD_LIBRARY_PATH=$DYLD_LIBRARY_PATH"
  381.   echo "     LIBRARY_PATH=$LIBRARY_PATH"
  382.   echo "       SHLIB_PATH=$SHLIB_PATH"
  383.   echo "          LIBPATH=$LIBPATH"
  384.   echo "       ADDON_PATH=$ADDON_PATH"
  385.   echo "      MOZ_PROGRAM=$MOZ_PROGRAM"
  386.   echo "      MOZ_TOOLKIT=$MOZ_TOOLKIT"
  387.   echo "        moz_debug=$moz_debug"
  388.   echo "     moz_debugger=$moz_debugger"
  389. fi
  390. #
  391. export MOZILLA_FIVE_HOME LD_LIBRARY_PATH
  392. export SHLIB_PATH LIBPATH LIBRARY_PATH ADDON_PATH DYLD_LIBRARY_PATH
  393.  
  394. if [ $moz_debug -eq 1 ]
  395. then
  396.     moz_debug_program ${1+"$@"}
  397. else
  398.     moz_run_program ${1+"$@"}
  399. fi
  400.  
  401. exit $exitcode
  402.